<?php
namespace Mp\Service\Widget;
use Illuminate\Contracts\Support\Renderable;
use Mp\Service\Widget\Input;

class Radio extends Input{

	protected $label = 'radio';

	protected $theme = "radiofill";  //radiofill  radio-inline

	protected $name = 'radio';

	protected $enable = true;

	protected $source = [];  //数据源

	protected $checks = [];

	protected $data = [];

	protected $view = 'Mp::widgets.radio';

	protected function _init($params){
		$this->label = $params['label'] ?? $this->label;
		$this->size = $params['size'] ?? $this->size;
		$this->type = $params['class'] ?? $this->class;
	
		$this->data = [
			'label' => $this->label,
			'size' => $this->size,
			'class' => $this->class,
			'source' => $this->source,
			'theme' => $this->theme,
			'enable' => $this->enable,
			'name' => $this->name,
		];
	}


	public function radio($params = []){
		$radio = [
			'value' => $params['value'],
			'checked' => false,
			'label' => $params['label'] ?? 'radio',
		];
		
		array_push($this->source , $radio);
		$this->data['source'] = $this->source;
		return $this;
	}

	public function checks($value=''){
		foreach($this->data['source'] as &$val){
			if($val['value'] == $value){
				$val['checked'] = true;
				break;
			}
		}
		return $this;
	}


	public function render(){
		$this->checks();
		 return  parent::render();
		
	}
}